import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';
import * as moment from 'moment';

/**
 * 文章信息
 */
@Entity('article_info')
export class ArticleInfoEntity extends BaseEntity {
  @Column({ comment: '标题', length: 255 })
  title: string;

  @Index()
  @Column({ comment: '分类ID' })
  categoryId: number;

  @Index()
  @Column({ comment: '作者ID' })
  authorId: number;

  @Column({ comment: '状态', dict: ['草稿', '已发布', '下架'], default: 0 })
  status: number;

  @Column({ comment: '排序值', default: 0 })
  order: number;

  @Column({ comment: '封面图', nullable: true })
  coverImage: string;

  @Column({ comment: '内容', type: 'text', nullable: true })
  content: string;

  @Column({ comment: '浏览数', default: 0 })
  viewCount: number;

  @Column({ comment: '点赞数', default: 0 })
  likeCount: number;

  @Column({
    comment: '发布时间',
    type: 'varchar',
    nullable: true,
    transformer: {
      to(value) {
        return value ? moment(value).format('YYYY-MM-DD HH:mm:ss') : null;
      },
      from(value) {
        return value;
      },
    },
  })
  publishTime: Date;
}
